** Data reading and variable selection from raw data
** Family Survey of the Dutch Population (Family-enquete Nederlandse Bevolking) 1998


** 01. Reading data **
cap log close
clear all
set more off
cd /*insert you work directory here*/
use /*read your data here*/ 


** 02. Consructing year and country variables **

ge year=1998
lab var year "survey year"

ge country=528
lab var country "ISO country code"
//Netherlands: 528 (see "ISO Country Codes.pdf) 


** 03. ID variables **

ge pid=respnr
lab var pid "respondent id"

ge fid=hhnr
lab var fid "family id"


** 04. Basic Demographics (Sex and Age/birth year) **

rename sex asex
recode asex (1=1 "male")(2=2 "female"),into(sex)
lab var sex "sex"

lab var age "age"

ge birthyr=year-age
lab var birthyr "year of birth"


** 05. Siblings **

ge nbro=d1_br
lab var nbro "number of brothers"
ge nsis=d1_zz
lab var nsis "number of sisters"

ge nsibs=nbro+nsis
lab var nsibs "number of siblings"

ge birthorder=d1bo
lab var birthorder "birth order of the respondent"


** 06. Own education **

//level of education
//Translated by Google
tab educlev
ge educ=educlev
lab var educ "level of education of the respondent"

lab def educ 1 "elementary school" 2 "lbo, huishoudschool, vbo" 3 "mavo, ulo, mulo" 4 "havo, mms" ///
5 "grammar school" 6 "kort mbo (kmbo)" 7 "volledig mbo" 8 "college/bachelor's degree" 9 "university" 10 "postgraduate"

lab val educ educ


** 07. Parents' education: Father and/or Mother **

//level of education
//Translated by Google
ge faeduc=b16_v
lab var faeduc "father's highest education obtained"
ge moeduc=b16_m
lab var moeduc "mother's highest education obtained"
lab val faeduc moeduc educ


** 08. Own occupation **

ge occ_ISEI=sei
lab var occ_ISEI "respondent's occupation for current/last occupation in ISEI codes"

ge ind_SBI=sbi
lab var ind_SBI "respondent's industry for current/last occupation in SBI codes"

ge pre_US=us
lab var pre_US "prestige score for current/last occupation in US codes"

ge class_EGP=egp
lab var class_EGP "class for current/last occupation in EGP codes"


** 09. Parents' occupation **
//Translated by Google
//father
ge fawork=b18_i
lab var fawork "if father's participating the labour market NOW"
lab def fawork 1 "yes" 2 "no"
lab val fawork fawork

ge fasup15=b19
lab var fasup "father's supervising status when the respondent is 15 years"
lab def fasup 1 "no subordination" 2 "1-2 subordinate" 3 "3-10 subordinates" 4 "11-24 subordinates" 5 "25 or more subordinates"
lab val fasup fasup

ge faempstat15=b20
lab var faempstat15 "father's employment type when the respondent is 15 years"
lab def faempstat15 1 "employeed to business" 2 "employed (semi) government" 3 "own account/independent" 4 "family helper"
lab val faempstat15 faempstat15

//mother
ge moworkps=b21
lab var moworkps "if mother participated the labour market when the respondent was in pre-school"
lab def moworkps 1 "no" 2 "yes, less than 12 hours per week" 3 "yes, more than 12 hours per week"
lab val moworkps moworkps

ge moworkpri=b22
lab var moworkpri "if mother participated the labour market when the respondent was in primary school"
lab val moworkpri moworkps

ge mowork12=b23
lab var mowork12 "if mother participated the labour market when the respondent was between 12-15 years"
lab val mowork12 moworkps

ge mowork=b23n
lab var mowork "if mother's participating the labour market NOW"
lab def mowork 1 "yes" 2 "no"
lab val mowork mowork


** 10. Tabulate the Identified Variables **

log using /*insert you work directory here*/, replace text

** Data reading and variable selection from raw data
** Family Survey of the Dutch Population (Family-enquete Nederlandse Bevolking) 1998

** Sex **
tab sex

** Age, Birth Year **
sum age birthyr, d

** Siblings **
sum nsibs nbro nsis birthorder, d

** R's Own Education **
tab1 educ 

** Parental Education **
tab1 faeduc moeduc 

** R's Own Occupation **
tab1 occ_ISEI ind_SBI pre_US class_EGP 

** Parental Occupation **
tab1 fawork fasup15 faempstat15 mowork moworkps moworkpri mowork12


log close

** 11. Keep the identified variables only

keep year country fid sex age birthyr ///
	 nsibs nbro nsis birthorder ///
	 educ faeduc moeduc ///
	 occ_ISEI ind_SBI pre_US class_EGP ///
	 fawork fasup15 faempstat15 mowork moworkps moworkpri mowork12


** 12. Save the Data File **

saveold /*insert you work directory here*/, replace



** 13. Homoginising education **
** Own Education **
rename educ educ_cat

ge educ_yrs=6 if educ_cat==1
replace educ_yrs=9 if educ_cat==2
replace educ_yrs=10 if educ_cat==3
replace educ_yrs=11 if educ_cat==4
replace educ_yrs=12 if educ_cat==5
replace educ_yrs=10 if educ_cat==6
replace educ_yrs=10.5 if educ_cat==7
replace educ_yrs=15 if educ_cat==8
replace educ_yrs=17 if educ_cat==9
replace educ_yrs=21 if educ_cat==10
lab var educ_yrs "respondent highest education in years"

ge educ_ISCED=100 if educ_cat==1
replace educ_ISCED=254 if educ_cat==2
replace educ_ISCED=244 if educ_cat==3
replace educ_ISCED=300 if educ_cat==4
replace educ_ISCED=300 if educ_cat==5
replace educ_ISCED=353 if educ_cat==6
replace educ_ISCED=354 if educ_cat==7
replace educ_ISCED=500 if educ_cat==8
replace educ_ISCED=600 if educ_cat==9
replace educ_ISCED=747 if educ_cat==10
lab var educ_ISCED "respondent highest education in ISCED code"

** Parents Education **

ge faeduc_flag=1 

rename faeduc faeduc_cat
rename moeduc maeduc_cat

ge faeduc_yrs=6 if faeduc_cat==1
replace faeduc_yrs=9 if faeduc_cat==2
replace faeduc_yrs=10 if faeduc_cat==3
replace faeduc_yrs=11 if faeduc_cat==4
replace faeduc_yrs=12 if faeduc_cat==5
replace faeduc_yrs=10 if faeduc_cat==6
replace faeduc_yrs=10.5 if faeduc_cat==7
replace faeduc_yrs=15 if faeduc_cat==8
replace faeduc_yrs=17 if faeduc_cat==9
replace faeduc_yrs=21 if faeduc_cat==10
lab var faeduc_yrs "father's education in years"

ge maeduc_yrs=6 if maeduc_cat==1
replace maeduc_yrs=9 if maeduc_cat==2
replace maeduc_yrs=10 if maeduc_cat==3
replace maeduc_yrs=11 if maeduc_cat==4
replace maeduc_yrs=12 if maeduc_cat==5
replace maeduc_yrs=10 if maeduc_cat==6
replace maeduc_yrs=10.5 if maeduc_cat==7
replace maeduc_yrs=15 if maeduc_cat==8
replace maeduc_yrs=17 if maeduc_cat==9
replace maeduc_yrs=21 if maeduc_cat==10
lab var maeduc_yrs "mother's education in years"

ge faeduc_ISCED=100 if faeduc_cat==1
replace faeduc_ISCED=254 if faeduc_cat==2
replace faeduc_ISCED=244 if faeduc_cat==3
replace faeduc_ISCED=300 if faeduc_cat==4
replace faeduc_ISCED=300 if faeduc_cat==5
replace faeduc_ISCED=353 if faeduc_cat==6
replace faeduc_ISCED=354 if faeduc_cat==7
replace faeduc_ISCED=500 if faeduc_cat==8
replace faeduc_ISCED=600 if faeduc_cat==9
replace faeduc_ISCED=747 if faeduc_cat==10
lab var faeduc_ISCED "father highest education in ISCED code"

ge maeduc_ISCED=100 if maeduc_cat==1
replace maeduc_ISCED=254 if maeduc_cat==2
replace maeduc_ISCED=244 if maeduc_cat==3
replace maeduc_ISCED=300 if maeduc_cat==4
replace maeduc_ISCED=300 if maeduc_cat==5
replace maeduc_ISCED=353 if maeduc_cat==6
replace maeduc_ISCED=354 if maeduc_cat==7
replace maeduc_ISCED=500 if maeduc_cat==8
replace maeduc_ISCED=600 if maeduc_cat==9
replace maeduc_ISCED=747 if maeduc_cat==10
lab var maeduc_ISCED "mother highest education in ISCED code"


** 14. Homoginising sibling **
//cutoff
ge nsibs_flag=99
lab var nsibs_flag "cutoff of total number of siblings"
ge nsis_flag=99
lab var nsis_flag "cutoff of number of sisters"
ge nbro_flag=99
lab var nbro_flag "cutoff of number of brothers"

lab def nsib_flag 99 "no cutoff"
lab val nsis_flag nbro_flag nsibs_flag nsib_flag


** 15. Tab Education and Sibling Variables **
tab1 sex age birthyr
tab1 educ_cat educ_yrs faeduc_cat faeduc_yrs maeduc_cat maeduc_yrs faeduc_flag 
tab1 nsis nbro nsibs nsis_flag nbro_flag nsibs_flag


** 16. Save the Data File **

saveold /*insert you work directory here*/, replace
